package com.linkgie.galaxyframework.utils.reflect.adv;

import org.springframework.core.ResolvableType;

/**
 * 泛型反射的工具类；
 * 
 * @author Hike
 *
 */
public class GenericTypeUtils {

	/**
	 * @param clazz
	 * @param genericInterface 泛型接口类型;
	 * @return
	 */
	public static Class<?>[] resolveGenericTypes(Class<?> clazz, Class<?> genericInterface) {
		ResolvableType type = ResolvableType.forClass(clazz).as(genericInterface);
		if (type == null) {
			return null;
		}
		ResolvableType[] resolvableTypes = type.getGenerics();
		if (resolvableTypes == null) {
			return null;
		}
		Class<?>[] genericTypes = new Class<?>[resolvableTypes.length];
		for (int i = 0; i < genericTypes.length; i++) {
			if (resolvableTypes[i] == null) {
				genericTypes[i] = null;
			} else {
				genericTypes[i] = resolvableTypes[i].resolve();
			}
		}
		return genericTypes;
	}

}
